//https://api.dartlang.org/stable/2.2.0/dart-io/HttpClient-class.html

import 'dart:io';

main() {
  HttpClient client = new HttpClient();
  //*********方法***********/  
  //getUrl(Uri url) → Future<HttpClientRequest>  --get方式请求一个网址
  client.getUrl(Uri.parse('https://www.baidu.com/')).then((httpClientRequest) {
    //close() → Future<HttpClientResponse> --发起请求
    return httpClientRequest.close();
  }).then((httpResponse) {
    print(httpResponse.statusCode);//返回相应
  }).whenComplete((){
    client.close(force: true);//完成后关闭客户端，force为true时立即关闭
  }).catchError((e){
    print('连接失败:'+e.toString());
  });

  //

}
